//
//  ZXTabBarVC.swift
//  Swift_WeiBo
//
//  Created by dajie on 15/8/17.
//  Copyright (c) 2015年 dajie. All rights reserved.
//

import UIKit
class ZXTabBarVC: UITabBarController {

    @IBOutlet weak var zxTabBar: ZXTabBar!
    
    override func viewDidLoad()
    {
        super.viewDidLoad()
        //  添加控制器
        addChildViewControllers()
        self.zxTabBar.composeButton.addTarget(self, action: "composeBtnClick", forControlEvents: UIControlEvents.TouchUpInside)
    }

// MARK: - 发送微博按钮点击(按钮的点击不能写成私有的方法)
    func composeBtnClick()
    {
        print("点击了发送微博按钮")
    }
    
//    MARK: - 添加控制器
   private func addChildViewControllers()
    {
        addChildViewController(SBName: "Home", title: "首页", imageOrigin: "tabbar_home", selecteImage: "tabbar_home_highlighted", tabTitle: "首页")
        
        addChildViewController(SBName: "Message", title: "消息", imageOrigin: "tabbar_message_center", selecteImage: "tabbar_message_center_highlighted", tabTitle: "消息")
        
        addChildViewController(SBName: "Discover", title: "发现", imageOrigin: "tabbar_discover", selecteImage: "tabbar_discover_highlighted", tabTitle: "发现")

        addChildViewController(SBName: "Profile", title: "我", imageOrigin: "tabbar_profile", selecteImage: "tabbar_profile_highlighted", tabTitle: "我")

    }
    
   private func addChildViewController(SBName SBName : String, title : String, imageOrigin : String, selecteImage : String, tabTitle : String)
    {
        tabBar.tintColor = UIColor.orangeColor()
        let sb = UIStoryboard(name: SBName, bundle: nil)
        let nav = sb.instantiateInitialViewController() as! UINavigationController
        nav.topViewController!.title = title
        let image = UIImage(named: selecteImage)!.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        nav.tabBarItem.image = UIImage(named:imageOrigin)
        nav.tabBarItem.selectedImage = image
        addChildViewController(nav)
    }

}
